﻿(function () {

    function getCurrentDate() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var date2 = date.getDate();

        var str = "";
        str += year.toString();
        if (month < 10) {
            str += "-0" + month.toString();
        } else {
            str += "-" + month.toString();
        }
        if (date2 < 10) {
            str += "-0" + date2.toString();
        } else {
            str += "-" + date2.toString();
        }

        return str;
    }

    var EOrderStatus = {
        Unpaid: 0           // 未付款
        , Paid: 1           // 已付款
        , RecvPayment: 2    // 已收款
        , Fetch: 3          // 已提货
    };

    var orderStatusArr = [
        { value: EOrderStatus.Unpaid, text: "未付款" },
        { value: EOrderStatus.Paid, text: "已付款" },
        { value: EOrderStatus.RecvPayment, text: "已收款" },
        { value: EOrderStatus.Fetch, text: "已提货" }
    ];
    function getOrderStatusArr() {
        return orderStatusArr;
    }
    function getOrderTextStatusArr() {
        var arr = [];
        orderStatusArr.forEach(item => arr.push(item["text"]));
        return arr;
    }
    function getOrderValuetStatusArr() {
        var arr = [];
        orderStatusArr.forEach(item => arr.push(item["value"]));
        return arr;
    }
    function getOrderStatusTextByValue(value) {
        var result = "";
        for (var i = 0; i < orderStatusArr.length; i++) {
            if (orderStatusArr[i]["value"] == value) {
                result = orderStatusArr[i]["text"];
                break;
            }
        }
        return result;
    }
    function getOrderStatusValueByText(text) {
        var result = "";
        for (var i = 0; i < orderStatusArr.length; i++) {
            if (orderStatusArr[i]["text"] == text) {
                result = orderStatusArr[i]["value"];
                break;
            }
        }
        return result;
    }

    window.tool = {};
    tool.getCurrentDate = getCurrentDate;

    tool.EOrderStatus = EOrderStatus;
    tool.getOrderStatusArr = getOrderStatusArr;
    tool.getOrderTextStatusArr = getOrderTextStatusArr;
    tool.getOrderValuetStatusArr = getOrderValuetStatusArr;
    tool.getOrderStatusTextByValue = getOrderStatusTextByValue;
    tool.getOrderStatusValueByText = getOrderStatusValueByText;

})();